import { toJS } from 'mobx';
import { requiredPngImg } from '.';
export default class WeaInputCellType extends GC.Spread.Sheets.CellTypes.Text {
    typeName = 'WeaSelectReadonlyCellType';
    fieldType;
    viewAttr =2;
    label;
    value;
    expandType;
    items;
    combineSameCell;
    id;
    multilang;
    fieldVisible;
    paint(ctx, value, x, y, w, h, style, context) {
        if(this.fieldVisible == '1') {
            this.viewAttr = 1;
            return;
        }
        if (!ctx) {
            return;
        }
        super.paint(ctx, value, x, y, w, h, style, context);
        if (this.viewAttr == 3) {
            if (value || value === 0) {
            } else {
                ctx.drawImage(requiredPngImg, x + w - 8, y + (h - 7) / 2, 7, 7);
            }

        }

    }

    fromJSON(setting) {
        this.fieldType = toJS(setting.fieldType)
        this.viewAttr = setting.viewAttr;
        this.fieldVisible = setting.fieldVisible;
        this.expandType = setting.expandType;
        this.combineSameCell = setting.combineSameCell;
        this.label = setting.label;
        this.id = setting.id;
        this.multilang = setting.multilang;
        if (this.fieldType && this.fieldType.length > 2) {
            const { datas = [] } = this.fieldType[2] || {};
            this.items = datas.map((d) => ({ text: d.selectName, value: '' + d.selectValue }));
        }
    }

    // 只读状态的下拉框
    format(value, format, formattedData, context) {
        if (value && this.items) {
            const v = this.items.filter(d => d.value+'' == value+'').map(d => d.text).join(',');
            return v;
        } else {
            return '';
        }
    }

    doUpdateValue = () => {

    }
    toJSON = (setting) => {
        let res =  super.toJSON();
        res.viewAttr = this.viewAttr;
        res.fieldVisible = this.fieldVisible;
        res.label = this.label;
        res.expandType = this.expandType;
        res.combineSameCell = this.combineSameCell;
        res.multilang = this.multilang;
        return res;
     }
}